<?php
/**
 * Created LI
 * Date: 2016/4/20
 * Time: 22:19
 */
namespace Admin\Controller;
use Think\Controller;
use Think\Upload;
class DoctorController extends Controller{
    public function __construct()
    {
        parent::__construct();
        if(!$_SESSION['admin_login']){
            $this->error('请登录','Index/login');
        }
    }

    public function doctor_list(){
        $model_doctor = D('Doctor');

        $condition = array();
        if($_POST['pet_name']){
            $condition['Name'] = $_POST['pet_name'];
        }
        if($_POST['category']) {
            $condition['Category'] = $_POST['category'];
        }

        $doctor_list = $model_doctor -> getDoctorList($condition,'*');
        foreach($doctor_list as $k => $v){
            $user = D('User') ->getUserInfo(array('Id' => $v['userid']));
            $doctor_list[$k]['user_name'] = $user['loginname'];
        }
        $this -> assign('doctor',$doctor_list);
        self::profile_menu('doctor_list');
        $this -> display('doctor.list');
    }
    /**
     * 删除百科
     */
    public function del(){
       if($_POST['id'] == 0){
           echo 'false';
       }
        $model_doctor = D('Doctor');
        $result = $model_doctor -> delDoctor(array('Id' => $_POST['id']));
        if($result){
            echo 'true';
        }else{
            echo 'false';
        }
    }
    /**
     * 删除百科
     */
    public function verify(){
       if($_POST['id'] == 0){
           echo 'false';
       }
        $param = array();
        if($_POST['if_pass'] == 'pass'){
            $param['IfPass'] = 1;
        }else{
            $param['IfPass'] = 2;
        }
        $model_doctor = D('Doctor');
        $result = $model_doctor -> updateDoctor(array('Id' => $_POST['id']),$param);
        if($result){
            echo 'true';
        }else{
            echo 'false';
        }
    }
    /**
     * 导航
     */
    private function profile_menu($key){
        $menu_array = array(
            'doctor'=>array('menu_key'=>'doctor','menu_name'=>'医生管理','menu_url'=>'index.php/admin/doctor/doctor_list'),
        );
        switch($key){
            case 'doctor_list':
                $menu_array['doctor']['child'] = array('menu_key'=>'doctor_list','menu_name'=>'医生列表','menu_url'=>'index.php/admin/doctor/doctor_list');
                break;
        }
        $this -> assign('menu_array',$menu_array);
    }
}